 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设置权限 </title>
    <link href="../../rs/css/bootstrap.min.css" rel="stylesheet">
    <link href="../../rs/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap_tab/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">

    <link href="../../rs/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    
     <?php
      require_once('login.php');
     ?>    
</head>
<body class="gray-bg">

<div class="row" style="padding:10px;border:1px solid #ccc">
    <div class="col-sm-4"  >
        <div class="input-group " style="padding-left:18px;">
				<span class="input-group-btn">
					<button style="margin-right: -2px;height:34px;  font-size: 14px" type="button" class="btn ">权限组</button>
				</span>
            <select class="form-control" id="qxz"></select>
            <span class="input-group-btn">
    					<button style="margin-right: -2px;height:34px;  font-size: 14px" type="button" class="btn" onclick="f_getdata()">查询</button>
    				</span>

        </div>
    </div>
    <div class="col-sm-4"></div>
    <div class="col-sm-4">

        <div class="input-group ">
                <span class="input-group-btn" style="padding-right:10px">
                        <button style="margin-right: 10px;height:34px;font-size: 14px;float:right" type="button" class="btn  btn-danger " onclick="save_data()"> 保存</button>

				</span>
        </div>
    </div>
</div>

<div class="wrapper wrapper-content" id="demo" style="background: #fff;">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content mailbox-content" style="padding-top:0px">
                    <div class="file-manager" >



<div v-cloak v-for="(index1,item) in mydata.data">
    <h3>{{item.mc}}</h3>
    <table class="table" >
    <tbody>
    <tr    v-cloak v-for="(index2,item1) in item.sub">
        <td class="checkbox-primary">
            <span class="checkbox " style="width:200px">
                <input v-cloak  v-model="item1.mqx" onclick="checkboxOnclick({{item1.rid}})" type="checkbox"   id="mqx{{item1.rid}}" val="{{item1.mc}}{{index1}}{{index2}}" f="{{item1.rid}}">
                <label for="mqx{{item1.rid}}">{{item1.mc}}</label>
            </span>
        </td>


        <td class="checkbox-primary"  v-if="test1(item1.qxc)">
            <span   class="checkbox checkbox-inline" v-for="(index3,select3) in item1.qxc">
                <input v-cloak v-model="test(item1.sqx,select3+',')"  id="sqx{{item1.rid}}{{select3}}"   f="{{item1.rid}}" name="sqx{{item1.rid}}" type="checkbox" value={{select3}} onclick="checkboxOnclick({{item1.rid}})"  />
                <label  for="sqx{{item1.rid}}{{select3}}">{{select3}}</label>
            </span>
        </td>
        <td class="checkbox-primary"  v-else>

        </td>

    </tr>
    </tbody>
    </table>
</div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../../rs/js/jquery.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/js/jquery.cookie.js"></script>
<script src="../../rs/js/common_qj.js"></script>
<script src="../../rs/js/vue.min.js"></script>
<script>

    var sign = URLencode($.cookie('sign'));
    $(function(){
        if(sign==="undefined"){
            window.location.href = "login.html";
        }
        get_sygr()
    });
    var demo = new Vue({
        el: '#demo',
        data: {
            mydata: ''
        }, methods: {
            test:function (a,b){
                if(a.indexOf( b )>=0 ) {  return true; }else{ return false;}
              },
              test1:function (n){
                if(n !=" ") {  return true;}
                }
        }

    });



    //获取数据
    function f_getdata(){
        var grid=$('#qxz').val(); //获取选择的权限组号
        $.ajax({
            type: "post",
            url:G_url+'sype/see/'+grid+'?sign='+sign,
            data: 'sign=' + sign,
            dataType: "json",

            success: function (result){
                if (result.ok) {
                    demo.mydata=result;
                }else{
                window.location.href = 'login.html';
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });


    }




    //获取权限组数据
    function get_sygr(){
        $.ajax({
            type: "post",
            url:G_url+'doi/see/sygr',
            data: 'sign=' + sign,
            dataType: "json",
            success: function (data){
                //给门店编号做循环
                var ff = data.data;
                var html = '';
                $.each(ff, function (a, b) {//直接取出json的prolist做each循环.
                    html += "<option value='"+b.rid+"'>" + b.mc + "</option>";//拼接字符串.
                });
                $("#qxz").append(html);

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

var dt=[];
function checkboxOnclick(rid){
var a={};
var sqx='';
 $('input[name=sqx'+rid+']:checked').each(function(){
     sqx +=$(this).val()+",";
 });

  var mqx_chk=$('input[id=mqx'+rid+']').is(':checked');
  if(mqx_chk==true){mqx=1}else if(mqx_chk==false){mqx=0};
    a.rid=rid;
    a.mqx=mqx;
    a.sqx=sqx;
    dt["'"+a.rid+"'"]=a;
}

    function  save_data(){
        var ar=[];
        var grid=$('#qxz').val(); //获取选择的权限组号
        for(var key in dt){
            var t=dt[key];
            ar.push(t);
        }

        $.ajax({
            type: "post",
            url:G_url+'sype/save'+'/'+grid+'/?sign='+sign,
            data:JSON.stringify(ar),
            dataType: "json",
            success: function (result){
                if (result.ok){
                    f_getdata();
                    layer.msg(result.msg);
                } else {
                  layer.msg(result.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });

    }



</script>

</body>


</html>
